
# with open('./text.txt','r',encoding='utf-8') as f:
#     result = f.read()
#     print(result.count('Python'))



# print(file.readlines())
# print(file.readline(),end='')



# 练习题1
# with open('./text.txt','r',encoding='utf-8') as f:
#     res = f.read()
#     print(res)
#     str_list = res.split('\n')
#     count = 0
#     for i in str_list:
#         count += 1
#     print(f"总行数为:{count}")
  


# 练习题2
# with open('./my_diary.txt','r',encoding='utf-8') as f:
#     file = f.readlines()
#     print(file)
#     keyword = "Python"
#     for line_number, line in enumerate(file, start=1):
#         if keyword in line:
#             print(f"在第 {line_number} 行找到关键词：{keyword}")
#         else:
#             print(f"在第 {line_number} 行未找到相关记录")



# 练习题1 基础文件写入
# with open('./my_diary2.txt','w',encoding='utf-8') as f:
#     s = """2023-10-1 晴\n今天学习了python文件操作"""
#     f.write(s)



# 练习题2 动态内容写入
# date = input("请输入今天的日期:")
# weather = input("记录天气:")
# text = input("请编写日记:")

# # 今天心情很好，去游泳了，下午又去网吧上个网，网上和好兄弟喝酒烤鸭
# with open('./my_diary3.txt','w',encoding='utf-8') as f:
#     f.write(f"{date}{weather}\n")
#     f.write(f"{text.replace('.','\n\n')}")
